#!/bin/bash

set -ex

SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"

cd "$SCRIPT_DIR" || exit 1

pushd .. >/dev/null
[[ -L "node_modules" ]] && rm "node_modules" || true
ln -s "$SCRIPT_DIR/node_modules" node_modules
yarn
"$(npm bin)"/grpc_tools_node_protoc -I. --js_out=import_style=commonjs,binary:node --grpc_out=grpc_js:node bentoml/grpc/v1alpha1/service.proto
rm node_modules
popd >/dev/null
